Skip to content

Mixed-model RESI confidence intervals (lmer and lme) - #57

Merged
simonvandekar merged 7 commits into
masterfrom
mixed-resi-ci
Nov 20, 2026
Merged

simonvandekar merged 7 commits into
masterfrom
mixed-resi-ci

Conversation

@simonvandekar

Copy link
Copy Markdown
Contributor

Adds asymptotic confidence intervals for RESI in linear mixed models (lmerMod, nlme::lme), targeting the Lyu–Welsh large-cluster limit.

Changes

  • .resi_ci_mixed(): normal, quadratic-form (QF) and characteristic-function (CF) intervals for coefficients and ANOVA terms.
    • Model-based or robust (CR2) covariance; the variance of the RESI SE is from a numerical Hessian.
    • Includes the design term.
  • Fast CR2 that handles singular fits (theta = 0), checked against clubSandwich for random slopes and singular fits.
  • Finite-df reference: robust (CR2) intervals default to a t(g−1) reference (ref.df = NULL); model-based intervals stay normal.
    • Implemented in the noise-only t form, integrated with a 20-node generalized Gauss–Laguerre rule.
  • QF 1-df interval: always uses the exact (Z + √ncp)² identity. This fixes a sign error that appeared for large statistics.
  • Sample-size rule for random slopes (child-level random effects); simulations generalized accordingly.
  • Tests: finite-df tail probabilities (absolute tolerance), CR2 vs clubSandwich, lme parity. Full suite passes (229).

Validation (AIgams repo, branch mixed-resi-ci: resiLongCalibrationSim/calibration_report.html)

  • Hybrid plasmode on mlmRev::egsingle:
    • Model A, 4×3 grid of g × m: QF/CF coverage 0.944–0.959, model-based.
    • CR2-t coverage: 0.91–0.92 at g = 15, rising to 0.94 at g = 100.
    • Model B (random slope) coverage: 0.94–0.97.
  • Out-of-sample check on mlmRev::star.

Known limitation: CR2 undercovers for random-slope terms at g = 15.

simonvandekar and others added 5 commits November 15, 2026 16:17
- R/resi_mixed_ci.R: asymptotic Var(RESI) from school-level influence values
  (outcome noise, random design incl. unit counts, sandwich meat, and the
  variance-component term for the model-based covariance), feeding the
  existing normal/QF/CF intervals; fast exact CR2 (.mixedCiCR2) used for
  clubSandwich::vcovCR(type = "CR2") on unweighted lmerMod fits.
- resi.lmerMod gains ci.method and ci.design and returns interval columns.
- R/mixed_simulations.R: hybridPlasmodeSim() and Lyu-Welsh limit helpers.
- Fix the sign of the large-noncentrality branch in .resi_ci_qf.
- Mixed point-estimate fixes (n level labels), print rounding, tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ngular fits against clubSandwich

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- .mixedCiBaseLme(): lme4-style representation (X, y, Zt, Lambdat, Lind,
  theta, sigma) of an lme fit, reproducing lme's beta, vcov and logLik; theta
  respects pdDiag/pdIdent constraints. Fits with varFunc/corStruct or other
  pdMat classes fall back to point estimates with a warning.
- resi.lme gains ci.method/ci.design; resi.lme and resi.lmerMod share
  .resiMixedWithCi(). ANOVA heading preserved.
- Fast exact CR2 also used for supported lme fits.
- Tests: lme vs lmer intervals agree; lme CR2 equals clubSandwich.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…asmode skips rank-deficient replicates

- .resi_ci_qf (m1 = 1): P(chi2_1(ncp) >= q) = pnorm(sqrt(ncp) - sqrt(q)) +
  pnorm(-sqrt(ncp) - sqrt(q)) for all q and ncp. pnchisq warned about lost
  precision for moderately large arguments and returned 0 in far tails.
- hybridPlasmodeSim: replicates whose resampled design loses a factor level
  (rank-deficient refit) are counted as failed fits.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…opes

- .resi_ci_mixed(ref.df = NULL): g - 1 for cluster-robust (CR2) intervals,
  normal otherwise. Normal/QF/CF/signed-CF support a finite reference df;
  QF/CF use t noise with an unscaled signal, integrated over W ~ chi^2_d with
  20-node generalized Gauss-Laguerre quadrature.
- resi_pe for mixed models: random-slope terms use the number of units at
  the slope level as n.
- hybridPlasmodeSim/lyuLimitResi support child-level random effects.
- Tests for the finite-df intervals and CR2 t widths.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
simonvandekar and others added 2 commits November 19, 2026 09:46
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@simonvandekar
simonvandekar merged commit 1ba4c70 into master Nov 20, 2026
1 check passed
@simonvandekar
simonvandekar deleted the mixed-resi-ci branch November 20, 2026 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant